﻿<Window x:Class="MBODM.WADM.UI.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ib="clr-namespace:MBODM.WPF;assembly=MBODM.WPF.InvertBoolExtension"
        xmlns:dn="clr-namespace:MBODM.WPF;assembly=MBODM.WPF.DisplayNameExtension"
        xmlns:ui="clr-namespace:MBODM.WADM.UI"
        Title="{Binding TextData[Title]}"
        Icon="/MBODM.WADM.UI;component/WADM.ico"
        Width="760"
        Height="550"
        MinWidth="525"
        MinHeight="330"
        WindowStartupLocation="CenterScreen"
        UseLayoutRounding="True"
        SnapsToDevicePixels="True"
        TextOptions.TextFormattingMode="Display">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <!-- ROW 0 -->
        <Label Grid.Row="0"
               Grid.Column="0"
               Grid.ColumnSpan="4"
               Margin="5,0,0,0"
               Padding="0,0,0,1"
               HorizontalAlignment="Left"
               VerticalAlignment="Bottom"
               Content="{Binding TextData[Folder]}"
               IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
        </Label>
        <Button Grid.Row="0"
                Grid.Column="0"
                Grid.ColumnSpan="4"
                Margin="0,5,5,5"
                Width="85"
                Height="25"
                HorizontalAlignment="Right"
                Content="{Binding TextData[Search]}"
                Command="{Binding Search}"
                IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
        </Button>
        <!-- ROW 1 -->
        <TextBox Grid.Row="1"
                 Grid.Column="0"
                 Grid.ColumnSpan="4"
                 Margin="5,0,5,15"
                 Height="25"
                 VerticalContentAlignment="Center"
                 Text="{Binding DownloadFolder, UpdateSourceTrigger=PropertyChanged}"
                 IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
        </TextBox>
        <!-- ROW 2 -->
        <TextBlock Grid.Row="2"
                   Grid.Column="2"
                   Grid.ColumnSpan="2"
                   Margin="0,0,0,15"
                   HorizontalAlignment="Left">
            <Hyperlink TextDecorations="None"
                       Command="{Binding Config}"
                       IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
                <Run Text="{Binding TextData[Config]}"></Run>
                <!-- Do not change color on mouse hover BEGIN -->
                <Hyperlink.Style>
                    <Style TargetType="Hyperlink">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver"
                                     Value="True">
                                <Setter Property="Foreground"
                                        Value="{Binding RelativeSource={RelativeSource Self}, Path=Foreground}">
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Hyperlink.Style>
                <!-- Do not change color on mouse hover END -->
            </Hyperlink>
        </TextBlock>
        <!-- ROW 3 -->
        <Button Grid.Row="3"
                Grid.Column="0"
                Margin="5,0,5,5"
                Width="85"
                Height="25"
                Content="{Binding TextData[Download]}"
                Command="{Binding Download}"
                IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
        </Button>
        <ProgressBar Grid.Row="3"
                     Grid.Column="1"
                     Margin="0,0,5,5"
                     IsIndeterminate="{Binding IsDownloading}">
        </ProgressBar>
        <TextBlock Grid.Row="3"
                   Grid.Column="1"
                   Padding="0,0,0,3"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Foreground="DarkBlue"
                   Text="{Binding TextData[Status]}">
        </TextBlock>
        <Button Grid.Row="3"
                Grid.Column="2"
                Margin="0,0,5,5"
                Width="40"
                Height="25"
                Content="{Binding TextData[Add]}"
                Command="{Binding Add}"
                IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
        </Button>
        <Button Grid.Row="3"
                Grid.Column="3"
                Margin="0,0,5,5"
                Width="40"
                Height="25"
                Content="{Binding TextData[Del]}"
                Command="{Binding Del}"
                IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
        </Button>
        <!-- ROW 4 -->
        <ListView Grid.Row="4"
                  Grid.Column="0"
                  Grid.ColumnSpan="4"
                  Margin="5,0,5,5"
                  SelectionMode="Single"
                  ItemsSource="{Binding Addons}"
                  SelectedItem="{Binding SelectedAddon}"
                  Name="listView">
            <ListView.View>
                <GridView AllowsColumnReorder="False">
                    <!-- Checkbox GridViewColumn BEGIN -->
                    <GridViewColumn Width="Auto">
                        <GridViewColumnHeader Content="{dn:DisplayName ui:AddonData, Active}"
                                              Tag="Active"
                                              IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
                        </GridViewColumnHeader>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox Focusable="False"
                                          HorizontalAlignment="Center"
                                          IsChecked="{Binding Active, NotifyOnTargetUpdated=True}"
                                          IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.IsDownloading, Converter={ib:InvertBool}}">
                                </CheckBox>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <!-- Checkbox GridViewColumn END -->
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding AddonName, NotifyOnTargetUpdated=True}">
                        <GridViewColumnHeader Content="{dn:DisplayName ui:AddonData, AddonName}"
                                              Tag="AddonName"
                                              IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
                        </GridViewColumnHeader>
                    </GridViewColumn>
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding AddonUrl, NotifyOnTargetUpdated=True}">
                        <GridViewColumnHeader Content="{dn:DisplayName ui:AddonData, AddonUrl}"
                                              Tag="AddonUrl"
                                              IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
                        </GridViewColumnHeader>
                    </GridViewColumn>
                    <!-- Progress GridViewColumn BEGIN -->
                    <GridViewColumn>
                        <GridViewColumnHeader Content="{dn:DisplayName ui:AddonData, StatusText}"
                                              Tag="StatusText"
                                              IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
                        </GridViewColumnHeader>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                                        <ColumnDefinition Width="*"></ColumnDefinition>
                                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <ProgressBar Grid.Column="0"
                                                 Grid.ColumnSpan="3"
                                                 Maximum="100"
                                                 Margin="0"
                                                 Padding="0"
                                                 Background="White"
                                                 BorderThickness="0"
                                                 Value="{Binding DownloadPercentage, NotifyOnTargetUpdated=True}">
                                        <ProgressBar.Resources>
                                            <Style TargetType="{x:Type ProgressBar}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Value}"
                                                                 Value="0">
                                                        <Setter Property="Visibility"
                                                                Value="Hidden">
                                                        </Setter>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Error}"
                                                                 Value="True">
                                                        <Setter Property="Foreground"
                                                                Value="IndianRed">
                                                        </Setter>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </ProgressBar.Resources>
                                    </ProgressBar>
                                    <TextBlock Grid.Column="0"
                                               Margin="5,1,5,1"
                                               Padding="0"
                                               HorizontalAlignment="Left"
                                               Foreground="White"
                                               Text="{Binding StatusText}">
                                    </TextBlock>
                                    <TextBlock Grid.Column="2"
                                               Margin="5,1,5,1"
                                               Padding="0"
                                               HorizontalAlignment="Right"
                                               Foreground="White"
                                               Text="{Binding ReceivedData, StringFormat={}{0} KB}">
                                    </TextBlock>
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <!-- Progress GridViewColumn END -->
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding FileName, NotifyOnTargetUpdated=True}">
                        <GridViewColumnHeader Content="{dn:DisplayName ui:AddonData, FileName}"
                                              Tag="FileName"
                                              IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
                        </GridViewColumnHeader>
                    </GridViewColumn>
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding DownloadUrl, NotifyOnTargetUpdated=True}">
                        <GridViewColumnHeader Content="{dn:DisplayName ui:AddonData, DownloadUrl}"
                                              Tag="DownloadUrl"
                                              IsEnabled="{Binding IsDownloading, Converter={ib:InvertBool}}">
                        </GridViewColumnHeader>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
            <!-- The ListViewItem ContextMenu BEGIN -->
            <ListView.InputBindings>
                <KeyBinding Key="C" 
                            Modifiers="Control"
                            Command="{Binding Copy}">
                </KeyBinding>
            </ListView.InputBindings>
            <ListView.Resources>
                <ContextMenu x:Key="MyListViewItemContextMenu"
                             DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Path=DataContext}">
                    <MenuItem Header="Copy"
                              Command="{Binding Path=Copy}"
                              InputGestureText="STRG+C">
                        <MenuItem.Icon>
                            <Image Source="../../Resources/Copy.png"></Image>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </ListView.Resources>
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment"
                            Value="Stretch">
                    </Setter>
                    <Setter Property="ContextMenu"
                            Value="{StaticResource MyListViewItemContextMenu}">
                    </Setter>
                </Style>
            </ListView.ItemContainerStyle>
            <!-- The ListViewItem ContextMenu END -->
        </ListView>
    </Grid>
</Window>
